/***
 * 斗地主场景类
 */

var BaseScene = require('./../../FrameWork/BaseScene');
var UtilGameObject = require('./../../FrameWork/Utils/UtilGameObject');
var DdzhRoomRobot = require('./DdzhRoomRobot');
var PkSound = require('./../../PkCommon/PkSound');
cc.Class({
    extends: BaseScene,
    properties: {
        posHeads: [cc.Node],
        posShowUIs: [cc.Node],
        pkHandCardsCtr: {
            default: null,
            type: require('././../../PkCommon/Manager/BasePkHandCardsManager'),
            displayName: '扑克手牌管理类'
        },
        prefabGamingBtns: {
            default: null,
            type: cc.Prefab,
            displayName: '游戏中按钮'
        },
        // prefabYBQ: {
        //     default: null,
        //     type: cc.Prefab,
        //     displayName: '要不起'
        // },

        prefabCallScore: {
            default: null,
            type: cc.Prefab,
            displayName: '叫分'
        },
        prefabDouble: {
            default: null,
            type: cc.Prefab,
            displayName: '加倍'
        },
        prefabResultBtns: {
            default: null,
            type: cc.Prefab,
            displayName: '游戏结算按钮'
        },
        posMainLayer: {
            default: null,
            type: cc.Node
        }
    },
    onLoad() {
        PkSound.bgMusic();
        this.loadSubpackages(['PkCommonSound']);
        this.gamingBtnsCtr = UtilGameObject.getCtrByPrefabs(this.prefabGamingBtns, this.posMainLayer, "BaseGamingBtnsManager");

        this.callScoreCtr = UtilGameObject.getCtrByPrefabs(this.prefabCallScore, this.posMainLayer, "BaseCallScoreManager");
        this.doubleCtr = UtilGameObject.getCtrByPrefabs(this.prefabDouble, this.posMainLayer, "BaseDoubleManager");
        this.resultBtnsCtr = UtilGameObject.getCtrByPrefabs(this.prefabResultBtns, this.posMainLayer, "BaseResultBtnsManager");
        this.resultBtnsCtr.setPosShowNodes(this.posShowUIs);
        this.resultBtnsCtr.setHeadNodes(this.posHeads)
        this.node.on(cc.Node.EventType.TOUCH_START, function(event) {
            if (null != this.oldTouchTime) {
                var tmp = (Date.now() - this.oldTouchTime);
                if (tmp < 300) {
                    this.pkHandCardsCtr.actRemoveChoiceAll();
                    this.oldTouchTime = null;
                    return;
                }
            }
            this.oldTouchTime = Date.now();
        }, this);
        this._super();

        MgAdaptation.Inst().iphoneX(this.posMainLayer);
    },
    initTest() {
        var _ = require('./../../FrameWork/we_underscore')
        UtilGameObject.removeDemoBgAllChild();
        UtilGameObject.createDemoBtn([
            ['重新发牌', function() {
                this.doTest();
            }.bind(this)],
        ]);
        this.doTest();
    },
    doTest() {
        setTimeout(() => {
            window.g_room = new DdzhRoomRobot();
            window.g_room.setSelfSeatIdx(0);
            window.g_room.serverFirstSendCard();
        }, 100);

    }
});